package presentation.windows;

import presentation.UIUser;


/**
 * Shared Data between all GUI frames.
 * changes in this data will be visible to all the frames that holding it.
 */
public class SharedUIData
{
	/** the current active user that is connected to the forum (guest or member) **/
	private UIUser user;

	/** indicates if the user is a logged-in member **/
	private boolean isLoggedIn;

	/**
	 * constructor.
	 * is used by the constructor of the main frame to initialize the first UIUser
	 * that was returned from the server after connecting the forum.
	 * (when registering a guest)
	 * @param user - the guest that is now connected to the forum.
	 */
	public SharedUIData(final UIUser user)
	{
		this.user = user;
		this.isLoggedIn = false;
	}

	/**
	 * set the user in the shared UI data to the new UIUser that was received from the server
	 * (after login the system, or after registering guest that is done right after logout)
	 * @param newUser - the new UIUser to set
	 */
	public synchronized void setUser(final UIUser newUser)
	{
		this.user = newUser;
	}


	/**
	 * set the state of the current user to be logged in or logged out
	 * (for setting the icon indication)
	 * @param isNowLoggedIn login state of the user.
	 */
	public synchronized void setLoggedIn(final boolean isNowLoggedIn)
	{
		this.isLoggedIn = isNowLoggedIn;
	}

	/**
	 * @return the current user
	 */
	public synchronized UIUser getUser()
	{
		return this.user;
	}

	/**
	 * @return true if the current user is a logged-in member, and false otherwise
	 */
	public synchronized boolean isLoggedIn()
	{
		return this.isLoggedIn;
	}
}
